<?php
include '../config/auth.php';
function success($res){
    $result = [
        'error'=>0,
        'message'=>$res,
        'time' => time()
    ];
    return json_encode($result);
}

function error($msg){
    $data = [
        'error'=>1,
        'message'=>$msg
    ];
    return json_encode($data);
}

try {
    $db = new PDO('mysql:host=120.77.37.81;dbname=onlinechat','root','123456');
    $statement=$db->prepare('SELECT `user`.nickname,`user`.path,message_record.message,message_record.user_name,
message_record.time FROM message_record LEFT JOIN `user` on `user`.username=message_record.user_name 
 WHERE time>:time and room_id=:room_id ORDER BY message_record.time ASC ; ');
    $statement->execute([
        ':room_id'=> $_GET['id'],
        ':time'=> $_GET['lastTime']
    ]);
    $result=$statement->fetchAll();

} catch (PDOException $e) {
    die('程序出错');
}

echo success($result);